package com.tkmybatis.hfy.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.tkmybatis.common.GlobalConstant;
import com.tkmybatis.exception.ErrorType;
import com.tkmybatis.hfy.base.entity.Result;
import com.tkmybatis.hfy.sign.SignUtil;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
import com.alibaba.fastjson.JSON;



/**
 * 参数签名拦截
 * @author ywt
 */
@Component
public class SignInterceptor extends HandlerInterceptorAdapter {

//    @Value("")
//    private Boolean signInterceptor;

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
    	// 判断是否为Feign过来的请求
//    	String isFeign = request.getHeader("isFeign");
//    	if(!GlobalConstant.IS_FEIGN.equals(isFeign)) {
//    		if(!SignUtil.checkSign(request)) {
//        		String resJSON = JSON.toJSONString(Result.fail(ErrorType.SIGN_ERROR));
//                response.setContentType("application/json;charset=utf-8");
//                response.setContentLength((resJSON.getBytes("utf-8")).length);
//                response.setStatus(403);
//                response.getWriter().write(resJSON);
//                response.flushBuffer();
//        		return  false;
//        	}
//    	}
    	return true;
    }
    
    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView)
            throws Exception {
    }
    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception exception)
            throws Exception {
    	    
    }
}